﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HYI.SDBSERVER;

namespace SHRSYSTEM
{
    public partial class FMI_HDWARRING : SDBSERVER.FMSINGLE
    {
        //入口函数
        public static Int32 StartMe(string sMainPara, string sPara, string sUser, DBSERVER sDB)
        {
            StaticClass.Selectm_MainPara = sMainPara;
            StaticClass.SelectItemValue = sPara;
            StaticClass.SelectUser = sUser;
            StaticClass.myDB = sDB;
            return 0;
        }

        DBCache myCache = new DBCache();

        private int iGridView = 0;
        public FMI_HDWARRING()
        {
            InitializeComponent();
        }

        //查询代码
        protected override void OnSys04()
        {
            string sDate1 = uiDate1.Text;
            string sDate2 = uiDate2.Text;
            string SQL = "select a.fusedate,ISNULL(s.fpoint_name,'') fpoint_name,ISNULL(b.fequipmenttag, '') fconname"
              + "  ,ISNULL(c.fequipmenttag, '') fcabname"
              + "  ,ISNULL(d.fequipmenttag, '') fboxname"
              + "  , CONVERT(varchar(10), a.fbegdate, 108) fbegtime"
              + "  , CONVERT(varchar(10), a.fenddate, 108) fendtime"
              +"  , e.fdictname"
              +"  , a.fmessage"
              +"  from i_tc_hardwarewarring a"
              +"  left join i_ts_box b on a.fconbarcode = b.fequipmentbarcode"
              +"  left join i_ts_cabinet c on c.fequipmentbarcode = a.fcabbarcode"
              +"  left join i_ts_warehouse d on d.fequipmentbarcode = a.fboxbarcode"
              +"  left join s_ts_dict e on e.fdicttype = 3010 and e.fdictno = a.ftype"
              + "  left join a_ts_point s on b.fpoint_no = s.fpoint_no"
              + "  where 1=1  "
              +"  and convert(varchar(10),a.fusedate,120) between '" + sDate1 + "'"
              +"  and '" + sDate2 + "'";
            DataRowView dr1 = (DataRowView)cbfairitem.SelectedItem;
            if ((dr1 != null) && (cbfairitem.SelectedIndex > 0))
            {
                SQL = SQL + " and a.ftype=" + dr1.Row["fdictno"].ToString();
            }

            DataRowView dr3 = (DataRowView)cbfpoint_no.SelectedItem;
            if ((dr3 != null) && (cbfpoint_no.SelectedIndex > 0))
            {
                SQL = SQL + " and b.fpoint_no='" + dr3.Row["fpoint_no"].ToString() + "'";
            }

            DataRowView dr4 = (DataRowView)uibox.SelectedItem;
            if ((dr4 != null) && (uibox.SelectedIndex > 0))
            {
                SQL = SQL + " and b.fequipmentbarcode='" + dr4.Row["fequipmentbarcode"].ToString() + "'";
            }

            if (uicabbarcode.Text != "")
            {
                SQL = SQL + " and c.fequipmentbarcode='" + uicabbarcode.Tag.ToString() + "'";
            }

            SQL = SQL + "  order by a.fusedate";
            Qrytable = StaticClass.myDB.query(SQL);

            base.OnSys04();

            rowindex = -1;
        }

        private void FMI_HDWARRING_Load(object sender, EventArgs e)
        {
            sUser = StaticClass.SelectUser;
            string[] strArray = StaticClass.Selectm_MainPara.Split(new char[] { ';' });
            sMenu = strArray[1];

            //按钮控制
            sys01.Visible = false; sys01.Tag = "1";
            sys02.Visible = false; sys02.Tag = "1";
            sys03.Visible = false; sys03.Tag = "1";
            sys05.Visible = false; sys05.Tag = "1";
            sys07.Visible = false; sys07.Tag = "1";
            sys08.Visible = false; sys08.Tag = "1";
            sys09.Visible = false; sys09.Tag = "1";
            sys10.Visible = false; sys10.Tag = "1";
            sys11.Visible = false; sys11.Tag = "1";

            uiDate1.Text = DateTime.Now.ToString("yyyy-MM-dd");
            uiDate2.Text = DateTime.Now.ToString("yyyy-MM-dd");
            uicabbarcode.Tag = "";
            //下拉框
            DataTable myAirITEM = myCache.doGetDict("S_TS_DICT", "FDICTTYPE=3010");

            DataRow dr2 = myAirITEM.NewRow();
            dr2["fdictname"] = "请选择";
            dr2["fdictno"] = "0";
            myAirITEM.Rows.InsertAt(dr2, 0);
            cbfairitem.DataSource = myAirITEM;
            cbfairitem.DisplayMember = "fdictname";
            cbfairitem.ValueMember = "fdictno";
            cbfairitem.SelectedIndex = 0;

            DataTable myTs_Point = myCache.doGetDict("A_TS_POINT", "fpoint_flag=0");

            DataRow dr4 = myTs_Point.NewRow();
            dr4["fpoint_name"] = "请选择";
            dr4["fpoint_no"] = "0";
            myTs_Point.Rows.InsertAt(dr4, 0);
            cbfpoint_no.DataSource = myTs_Point;
            cbfpoint_no.DisplayMember = "fpoint_name";
            cbfpoint_no.ValueMember = "fpoint_no";
            cbfpoint_no.SelectedIndex = 0;

            DataTable myTs_BOX = StaticClass.myDB.query(" select fequipmentbarcode,fequipmenttag from i_ts_box");

            DataRow dr3 = myTs_BOX.NewRow();
            dr3["fequipmenttag"] = "请选择";
            dr3["fequipmentbarcode"] = "0";
            myTs_BOX.Rows.InsertAt(dr3, 0);
            uibox.DataSource = myTs_BOX;
            uibox.DisplayMember = "fequipmenttag";
            uibox.ValueMember = "fequipmentbarcode";

            uibox.SelectedIndex = 0;
            //执行查询代码
            OnSys04();

            //表格列显示统一控制
            if (iGridView == 0)
            {
                myCache.doSetGridVIew(sMenu, sUser, uiDGView);
                iGridView = iGridView + 1;
            }
        }

        private void cbfairitem_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        private void cbfpoint_no_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        private void uibox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        private void uiBtn1_Click(object sender, EventArgs e)
        {
            //弹窗选择储物柜
            uicabbarcode.Text = "";
            uicabbarcode.Tag = "";

            string DATA = doPOPWINDOS("储物柜查询"
                , "fequipmentbarcode,储物柜编号,121;fequipmenttag,储物柜名称,141"
                , "select fequipmentbarcode,fequipmenttag,fmacno from i_ts_cabinet where 1=1"
                , " order by fequipmentbarcode"
                , 0);
            Console.WriteLine("当前返回:" + DATA);

            if ((DATA is null) || (DATA.Length == 0))
            {
                return;
            }
            string[] strArray = DATA.Split(',');

            uicabbarcode.Text = strArray[1];
            uicabbarcode.Tag = strArray[0];
        }
    }
}
